#include <time.h>
#include "ch03.h"
const int BUF_SIZE = 1024;

int main(int argc, char *argv[])
{

    int n, from, to;
    char buf[BUF_SIZE];
    clock_t start, finish;
    double totalTime;
    if(argc != 3)
    {
        printf("Usage: %s from -file to file\n", argv[0]);
        exit(1);
    }
    if((from = open(argv[1], O_RDONLY)) < 0)
    {
        err_exit(argv[1]);
    }
    if((to = open(argv[2], O_WRONLY | O_CREAT | O_APPEND, 0644)) < 0)
    {
        err_exit(argv[2]);
    }

    start = clock();

    while((n = read(from, buf, sizeof(buf))) > 0)
    {
        write(to, buf, n);
    }
    finish = clock();
    totalTime = (double)(finish - start) / CLOCKS_PER_SEC;
    printf("BUF_SIZE为 %d 时，程序运行的时间: %f\n", BUF_SIZE, totalTime);
    close(from);
    close(to);

    return 0;
}